//package org.znxs.znxsframe.mq_test;
//
//import com.rabbitmq.client.*;
//
//public class DirectConsumer {
//
//    // 交换机名称
//    private static final String EXCHANGE_NAME = "direct_znxs";
//
//    public static void main(String[] argv) throws Exception {
//        // 创建连接
//        ConnectionFactory factory = new ConnectionFactory();
//        factory.setHost("localhost");
//        Connection connection = factory.newConnection();
//        Channel channel = connection.createChannel();
//
//        // 声明交换机
//        channel.exchangeDeclare(EXCHANGE_NAME, "direct");
//
//        // 创建声明队列1
//        String queueName1 = "yuangongxiaozhang";
//        channel.queueDeclare(queueName1, true, false, false, null);
//        // 绑定交换机与routingKey
//        channel.queueBind(queueName1, EXCHANGE_NAME, "xiaozhang");
//
//        // 创建声明队列2
//        String queueName2 = "yuangongxiaoli";
//        channel.queueDeclare(queueName2, true, false, false, null);
//        // 绑定交换机与routingKey
//        channel.queueBind(queueName2, EXCHANGE_NAME, "xiaoli");
//
//        System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
//
//
//        DeliverCallback xiaozhangDeliverCallback = (consumerTag, delivery) -> {
//            String message = new String(delivery.getBody(), "UTF-8");
//            System.out.println(" [x] Received '" +
//                    delivery.getEnvelope().getRoutingKey() + "':'" + message + "'");
//        };
//
//        DeliverCallback xiaoliDeliverCallback = (consumerTag, delivery) -> {
//            String message = new String(delivery.getBody(), "UTF-8");
//            System.out.println(" [x] Received '" +
//                    delivery.getEnvelope().getRoutingKey() + "':'" + message + "'");
//        };
//
//        // 消费
//        channel.basicConsume(queueName1, true, xiaozhangDeliverCallback, consumerTag -> {
//        });
//        channel.basicConsume(queueName2, true, xiaoliDeliverCallback, consumerTag -> {
//        });
//    }
//}